#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import utils.rand_kit as rand_kit

# 快速排序，复杂度O(n*log(2)n)
def quick_sort(arr):
    arr_len = len(arr)
    if(arr_len < 2):
        return
    else:
        mid = arr_len / 2
        mid_value = arr[mid]
        smaller_arr = []
        bigger_arr = []
        for i in range(arr_len):
            if(i == mid): continue
            if(arr[i] < mid_value):
                smaller_arr.append(arr[i])
            else:
                bigger_arr.append(arr[i])
        quick_sort(smaller_arr)
        quick_sort(bigger_arr)
        smaller_arr_len = len(smaller_arr)
        for i in range(smaller_arr_len):
            arr[i] = smaller_arr[i]
        arr[smaller_arr_len] = mid_value
        for i in range(len(bigger_arr)):
            arr[smaller_arr_len + 1 + i] = bigger_arr[i]
    
if __name__ == "__main__":
    arr = rand_kit.rand_arr()
    quick_sort(arr)
    print(arr)